package com.lemon.smartsafety.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.utils.CommonUtil;


/**
 * 项目名称：up_exec_law
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/6/22 14:25
 * 修改人：Fargo
 * 修改时间：2016/6/22 14:25
 * 修改备注：
 */
public class DialogHint {


    private TextView  txt_complete,txt_cancel,txtTitle,txtContent;
    private LinearLayout line_content;

    private Dialog hintDialog;
    private Context context;

    public DialogHint(Context context) {
        this.context = context;
    }

    public interface ClickBackInterface {
        public void callBackFunction(View v);

    }

    /**
     *
     */
    public  void init( String title, String content, final ClickBackInterface clickBackInterface) {
        if(context==null){
            return;
        }

        hintDialog = new Dialog(context, R.style.dialog_style);
        hintDialog.setContentView(R.layout.dialog_hint);
        Window win = hintDialog.getWindow();
        win.setGravity(Gravity.CENTER_VERTICAL);
        win.setWindowAnimations(R.style.DialogAnimationFade); // 设置窗口弹出动画
        win.setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        hintDialog.setCanceledOnTouchOutside(true);

        txt_cancel = (TextView) hintDialog.findViewById(R.id.txt_cancel);
        txt_complete = (TextView) hintDialog.findViewById(R.id.txt_complete);
        txtTitle = (TextView) hintDialog.findViewById(R.id.txtTitle);
        txtContent = (TextView) hintDialog.findViewById(R.id.txtContent);
        line_content = (LinearLayout) hintDialog.findViewById(R.id.line_content);


        if(!CommonUtil.strIsEmpty(title)){
            txtTitle.setText(title);
        }

        if(!CommonUtil.strIsEmpty(content)){
            txtContent.setText(content);
            line_content.setVisibility(View.VISIBLE);
        }else{
            line_content.setVisibility(View.GONE);
        }

        txt_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hintDialog.dismiss();
            }
        });


        txt_complete.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // MUtils.toast(context, "你点击了立即升级");
                        hintDialog.dismiss();
                        clickBackInterface.callBackFunction(v);

                    }
                });

        hintDialog.show();
    }




}
